DECLARE @TableName VARCHAR(128) = '<@TABLENAME,VARCHAR(128),>'

SELECT  C.object_id AS TableObjectID,
	   C.column_id AS ColumnID,
	   'CostShare' AS BusinessArea,
	   @TableName AS TableName,
	   C.name AS ColumnName,
	   EP.Description AS Definition,
	   T.name AS name,
	   T.max_length,
	   CASE WHEN T.is_nullable = 1 THEN 'Y' ELSE 'N' END AS Nullable
FROM	   sys.columns AS C
	   INNER JOIN sys.objects AS O ON (O.object_id = C.object_id)
	   OUTER APPLY (
				    SELECT  fn.objtype AS [Type],
						  fn.objname AS [Column],
						  fn.name AS [PropertyName],
						  fn.value AS [Description] 
				    FROM	  fn_listextendedproperty (NULL, 'schema', 'dbo', 'table', @TableName, 'column', default) AS fn
				    WHERE	  fn.objname = C.name COLLATE SQL_Latin1_General_Pref_CP1_CI_AS
				) AS EP 
	   INNER JOIN sys.types AS T ON (C.system_type_id = T.user_type_id)
WHERE   O.type = 'U'
	   AND O.name = @TableName
ORDER   BY column_id
			 
